refactor: enhance ByteBuffer.get performance#25
Merged
Conversation
|
@gxcsoccer, thanks for your PR! By analyzing the history of the files in this pull request, we identified @fengmk2, @dead-horse and @pmq20 to be potential reviewers. |
Member
|
前后 benchmark 对比呢? |
gxcsoccer
commented
May 10, 2017
| }; | ||
|
|
||
| ByteBuffer.prototype.get = function (index, length) { | ||
| if (index instanceof Buffer || Array.isArray(index)) { // get (byte[] dst, int offset, int length) |
Member
Author
There was a problem hiding this comment.
这个判断比较耗时,把它挪到后面去,在 hessian.js 里大部分情况是 get() 或者 get(index)
Member
Author
|
Member
Author
|
ping @fengmk2 |
dead-horse
approved these changes
May 11, 2017
dead-horse
reviewed
May 11, 2017
lib/byte.js
Outdated
| this.checkArraySize(dst.length, offset, length); | ||
| this.checkForUnderflow(length); | ||
|
|
||
| if (is.buffer(dst)) { |
Member
There was a problem hiding this comment.
直接用 Buffer.isBuffer() 吧,就不需要引入 is-type-of 了
fengmk2
reviewed
May 11, 2017
| // old get() x 2,234,273 ops/sec ±1.45% (90 runs sampled) | ||
| // new get() x 24,872,342 ops/sec ±2.13% (89 runs sampled) | ||
| // old get(index) x 2,339,452 ops/sec ±0.81% (93 runs sampled) | ||
| // new get(index) x 25,533,534 ops/sec ±0.84% (100 runs sampled) |
fengmk2
approved these changes
May 11, 2017
Member
|
@gxcsoccer 去掉 is-type-of 的依赖,你自己合并发布新版本。 |
Contributor
|
👏 赞 没想到 |
Member
Author
|
@fengmk2 加个权限 |
Member
|
@gxcsoccer done |
Member
Author
|
+ byte@1.1.6 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
调整一下 ByteBuffer.get 参数判断的顺序